import { createStore } from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import user from './modules/user';

export default createStore({
  state: {
    token: ''
  },
  getters: {
    getToken: state => state.token,
  },
  mutations: {
    setToken(state, newToken) {
      state.token = newToken;
    },
  },
  actions: {
    updateToken({ commit }, newToken) {
      commit('setToken', newToken);
    },
  },
  modules: {
    user,
  },
  plugins: [createPersistedState()] // 应用 vuex-persistedstate 插件
})
